package com.junzhiit.nengji.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.junzhiit.nengji.cms.service.SetMealService;
import com.junzhiit.nengji.cms.web.exception.SetMealNotFoundException;
import com.junzhiit.nengji.cms.web.util.ViewObjectUtil;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.SetMealVO;
import com.junzhiit.nengji.dao.SetMealDAO;
import com.junzhiit.nengji.model.SetMeal;

@Service
public class SetMealServiceImpl extends BaseServiceImpl implements SetMealService {

	@Autowired
	private SetMealDAO setMealDAO;
	
	@Override
	public Map<String, Object> findAll(DataTablesParamVO dtp, SetMealVO setMealVO) {
		SetMeal setMeal = new SetMeal();
		BeanUtils.copyProperties(setMealVO, setMeal);
		List<SetMeal> list =setMealDAO.findAll(setMeal,dtp.getStart(), dtp.getLength());
		int totalCount = setMealDAO.getTotalCount(setMeal);
		return ViewObjectUtil.dataTables(list, dtp.getDraw(), totalCount);
	}

	@Override
	public ResultVO add(SetMealVO setMealVO) {
		ResultVO result = new ResultVO();
		try {
			SetMeal setMeal = new SetMeal();
			BeanUtils.copyProperties(setMealVO, setMeal);
			setMealDAO.insert(setMeal);
		} catch (Exception e) {
			
		}
		return result;
	}

	@Override
	public ResultVO update(SetMealVO setMealVO) {
		ResultVO result = new ResultVO();
		try {
			SetMeal setMeal = setMealDAO.query(setMealVO.getId());
			if(setMeal == null){
				throw new SetMealNotFoundException("套餐为空");
			}
			BeanUtils.copyProperties(setMealVO, setMeal);
			setMealDAO.update(setMeal);
		} catch (Exception e) {
			
		}
		return result;
	}

	@Override
	public ResultVO delete(String id) {
		ResultVO result = new ResultVO();
		try {
			SetMeal setMeal = setMealDAO.query(id);
			if(setMeal == null){
				throw new SetMealNotFoundException("套餐为空");
			}
			setMealDAO.delete(id);
		} catch (Exception e) {
			
		}
		return result;
	}

	@Override
	public ResultVO getSetMealById(String id) {
		ResultVO result = new ResultVO();
		result.setData(setMealDAO.getSetMealById(id));
		return result;
	}

	@Override
	public ResultVO getSetMealList(SetMealVO setMealVO) {
		ResultVO result = new ResultVO();
		
		SetMeal setMeal=new SetMeal();
		BeanUtils.copyProperties(setMealVO, setMeal);
		
		result.setData(setMealDAO.getSetMealList(setMeal));
		return result;
	}

	@Override
	public ResultVO findAllConcise(SetMealVO setMealVO) {
		ResultVO result = new ResultVO();
		SetMeal setMeal=new SetMeal();
		BeanUtils.copyProperties(setMealVO, setMeal);
		result.setData(setMealDAO.findConciseAll(setMeal));
		return result;
	}

}
